package com.imaker.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.imaker.domain.Department;
import com.imaker.domain.RoleInfo;
import com.imaker.domain.UserInfo;
import com.imaker.domain.UserRoleInfo;
import com.imaker.service.DepartmentService;
import com.imaker.service.RoleService;
import com.imaker.service.UserRoleService;
import com.imaker.service.UserService;
/**
 * <p>程序名称：       UserAction</p>
 * <p>程序说明：     用户操作action</p>
 * <p>版权信息：       Copyright mayonghua</p>
 * 
 * @author：          mayonghua
 * @version：         Ver 0.1
 */
@Controller
@Scope("prototype")
public class UserAction extends BaseAction{

	@Autowired
	private UserService userService = null;
	@Autowired
	private DepartmentService departmentService = null;
	@Autowired
	private UserRoleService userRoleService = null;
	@Autowired
	private RoleService roleService = null;
	private List<UserRoleInfo> userRoleList;
	private List<RoleInfo> roleList;
	private UserInfo userInfo;
	private List<UserInfo> userList;
	private Department department;
	private List<Department> departmentList = null;
	/**
	 * 初始化
	 * @return
	 */
	public String init(){
		
		return SUCCESS;
	}
	
	/**
	 * 左边的类别树
	 * @return
	 */
	public String tree() throws Exception{
		departmentList = departmentService.findAll();
		getRequest().setAttribute("departmentList",departmentList);
		return SUCCESS;
	}
	
	/**
	 * 列表显示
	 */
	public String list() throws Exception{
		page  = userService.listByPage(page,department);
		return SUCCESS;
	}
	
	
	
	/**
	 * 预新建
	 * @return
	 */
	public String toSave() throws Exception{
		departmentList = departmentService.findAll();
		return SUCCESS;
	}
	
	/**
	 * 新建
	 * @return
	 */
	public String save(){
		userService.save(userInfo);
		return SUCCESS;
	}
	
	/**
	 * 预修改
	 * @return
	 */
	public String toUpdate() throws Exception{
		userInfo = userService.findById(userInfo.getId());
		return SUCCESS;
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String update(){
		userService.update(userInfo);
		return SUCCESS;
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String delete(){
		userService.delete(idList);
		return SUCCESS;
	}

	/**
	 * 设置用户角色
	 * @return
	 */
	public String userRole() throws Exception{
		roleList = roleService.findAll();
		userRoleList = userRoleService.findByUser(userInfo);
		return SUCCESS;
	}
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public List<UserInfo> getUserList() {
		return userList;
	}

	public void setUserList(List<UserInfo> userList) {
		this.userList = userList;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public DepartmentService getDepartmentService() {
		return departmentService;
	}

	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public List<Department> getDepartmentList() {
		return departmentList;
	}

	public void setDepartmentList(List<Department> departmentList) {
		this.departmentList = departmentList;
	}

	public UserRoleService getUserRoleService() {
		return userRoleService;
	}

	public void setUserRoleService(UserRoleService userRoleService) {
		this.userRoleService = userRoleService;
	}

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public List<UserRoleInfo> getUserRoleList() {
		return userRoleList;
	}

	public void setUserRoleList(List<UserRoleInfo> userRoleList) {
		this.userRoleList = userRoleList;
	}

	public List<RoleInfo> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<RoleInfo> roleList) {
		this.roleList = roleList;
	}
	
}
